<template>
  <div class="bg-white">
    <div class="container-title">
      <span class="big">账号积分: {{availableIntegral}}</span>
    </div>
    <homeTable
        :list="list" :translate='50'
        @getData="getData"
        @onPageSizeChange="onPageSizeChange"
        @onPageChange="onPageChange"
      />
    </TabPane>
  </div>
</template>
<script>
  import homeTable from '@/components/homeTable'

  export default {
    props: {
      form: {
        type: Object
      }
    },
    components: {
      homeTable
    },
    data() {
      return {
        list: {
          status: 'pass',
          totalItem: 1,
          pageSize: window.$pageSize,
          currentPage: 1,
          
          columns: [{
            title: '变更单号',
            key: 'orderNo',
            align: 'left',
          }, {
            title: '变更时间',
            key: 'createDate',
            align: 'left',
          }, {
            title: '变更前积分',
            key: 'beforeIntegral',
            align: 'left',
          }, {
            title: '变更后积分',
            key: 'afterIntegral',
            align: 'left',
          }, {
            title: '变更积分',
            key: 'changeIntegral',
            align: 'left',
          }, {
            title: '变更方向',
            key: 'directionName',
            align: 'left'
          }, {
            title: '变更备注',
            key: 'remark',
            align: 'left',
          }, {
            title: '任务是否完成',
            key: 'isComplete',
            align: 'left',
          }, {
            title: '审核备注',
            key: 'auditIntegralRemark',
            align: 'left',
          }],
          data: []
        },
        availableIntegral: 0
      }
    },
    mounted () {
      this.getData()
    },
    methods: {
      getData() {
        let storeId = this.form.storeDTO.id
        if(!storeId) return
        let param = {
          current: this.list.currentPage,
          size: this.list.pageSize,
          storeId
        };
        this.list.status = "loading";
        this.$ajaxGet(`/contract_store/detail_integral_list/${storeId}`, param).then(res => {
          this.availableIntegral = res.availableIntegral
          let data = res.storeIntegralAccountChangeLogQuery
          if(data) {
            this.list.data = (data.records || []).map(item => {
              return {
                auditIntegralRemark: item.auditIntegralRemark,
                isComplete: item.isComplete,
                ...item.storeIntegralAccountChangeLogDTO
              }
            })
            this.list.totalItem = Number(data.total);
          }
          this.list.status = "pass";
        })
        .catch(() => {
          this.list.status = "pass";
        });
      },
      onPageChange(number) {
        this.list.currentPage = number;
        this.getData();
      },
      onPageSizeChange(pageSize) {
        this.list.currentPage = 1;
        this.list.pageSize = pageSize;
        this.getData();
      },
    },
    computed: {

    }
  }
</script>
